package com.santiao.youxiang.ui.activity

import android.content.Context
import android.content.Intent
import android.content.pm.PackageManager
import android.os.Build
import android.os.Bundle
import android.widget.FrameLayout
import android.widget.ImageView
import android.widget.TextView
import androidx.annotation.RequiresApi
import androidx.appcompat.app.AppCompatActivity
import com.blankj.utilcode.util.ToastUtils
import com.gyf.immersionbar.ImmersionBar
import com.santiao.publics.ui.SettingFragment
import com.santiao.youxiang.R

class RYWaterSelectedActivity : AppCompatActivity(){
    val TAG = "WaterSelectedActivity"
    private lateinit var backImageView: ImageView
    private lateinit var changer_tv_selected: TextView

    private lateinit var function_container: FrameLayout
    @RequiresApi(Build.VERSION_CODES.M)
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.water_selected)
        ImmersionBar.with(this)
            .transparentStatusBar()
            .transparentNavigationBar()
            .init()
        initView()
        initViewSetting()
    }

    private fun initView(){
        backImageView=findViewById(R.id.risk_back_img)
        changer_tv_selected=findViewById(R.id.changer_tv_selected)
        function_container=findViewById(R.id.function_container)

        SettingFragment.adLoad(1,null,null,this,this)
    }

    @RequiresApi(Build.VERSION_CODES.M)
    private fun initViewSetting(){
        backImageView.setOnClickListener {
            finish()
        }


        changer_tv_selected.setOnClickListener({

            if(isWeChatInstalled(this@RYWaterSelectedActivity)){
                openWeChat(this@RYWaterSelectedActivity)
            }else{
                ToastUtils.showLong("请安装微信客户端！")
            }
            SettingFragment.adLoad2(1,null,null,this,this)
        })



    }




    fun isWeChatInstalled(context:Context): Boolean {
        var packageManager = context.getPackageManager();
        try {
            packageManager.getPackageInfo("com.tencent.mm", PackageManager.GET_ACTIVITIES);
            return true;
        } catch (e : PackageManager.NameNotFoundException) {
            return false;
        }
    }


    fun openWeChat(context:Context) {
        var intent = context.getPackageManager().getLaunchIntentForPackage("com.tencent.mm");
        if (intent != null) {
            intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            context.startActivity(intent);
        }
    }


    override fun onResume() {

        super.onResume()
    }


//    private fun requestPermission(){
//        XXPermissions.with(this)
//            .permission(Permission.ACCESS_FINE_LOCATION)
//            .request(object : OnPermissionCallback {
//                override fun onGranted(permissions: MutableList<String>, allGranted: Boolean) {
//                    Log.i("permission","request location permission SUCCESS")
//                }
//
//                override fun onDenied(permissions: MutableList<String>, doNotAskAgain: Boolean) {
//                    if (doNotAskAgain) {
//                        Log.i("permission","request location permission NEVER")
//                        PermissionDialog(this@ChargeSelectedActivity).show()
//                    }
//                    else {
//                        Log.i("permission","request location permission FAIL")
//                    }
//                }
//            })
//    }




}